	$(function(){
 				$('#dg').datagrid({    
   				 url:'admin/resource/listRows', 
   				 toolbar:'#tb',
   				 fit:true, 
   				 border:false,
   				 rownumbers:true,
   				 singleSelect:false,
   				 checkOnSelect:true,
   				 autoRowHeight:false,
   				 loadMsg:'加载中，请稍等...',
   				 striped:true,//显示斑马线
   				 idField:'id',//翻页时记住前面选的
   				 pagination:true,//显示底部分页工具栏
   				 pageSize:10,
   				 pageList:[10,20,30,40,50],
  				 columns:[[
  						 { field:'ck',checkbox:true },
		       			 {field:'id',title:'ID',width:'10%',sortable:true,hidden:true},    
		       			 {field:'resourceTitle',title:'标题',width:'15%'},    
		       			 {field:'resourceType',title:'类型',width:'15%'},
		       			 {field:'resourceSize',title:'大小',width:'10%'},
		       			 {field:'score',title:'所需积分',width:'7%'},
		       			 {field:'commentScore',title:'评分',width:'7%'},
		       			 {field:'isPass',title:'状态',width:'10%',
		       				 formatter: function(value,row,index){
		       					 var str = "";
		       					 switch(value){
		       					 case 0:
		       						 str = '审核中';
		       						 break;
		       					 case 1:
		       						 str = '通过';
		       						 break;
		       					 }
		       					 return str;
		       				 }
		       			 }, 
		       			 {field:'uploadDate',title:'上传日期',width:'15%',
		       				 formatter: function(value,row,index){
				        		 if(value != null){
			       			  			return formatDate(value);
			       			  		}
		       			 }},
		       			 {field:'resourceDescription',title:'文件描述',width:'18%'}
  		  					]]    
					}); 
 			});
 			
	var url = "";
	// 新增
    function add(){
    	$("#fm").form('clear');
    	$("#dlg").dialog("open").dialog("setTitle","添加文件信息");
    	url = 'admin/resource/save';
    }

	// 修改用户对话框
    function edit(){
		var rows=$("#dg").datagrid('getSelections');
		if(rows.length !=1){
			parent.$.messager.alert('系统提示','请选择一条要编辑的数据！');
			return;
		}
		var row=rows[0];
		$("#dlg").dialog("open").dialog("setTitle","修改文件信息");
		$("#fm").form("load",row);
		url = 'admin/resource/edit?id='+row.id;
	}
	
    // 关闭添加修改对话框
    function closeDialog(){
    	$("#fm").form('clear');
    	$("#dlg").dialog("close");
    }
    
    /**
     * 刷新
     */
    function refresh(){
    	$('#dg').datagrid('reload');
    	$('#dg').datagrid('clearChecked');
    }

	
 /**
 *删除
 */
 function del(){
 						 var row = $('#dg').datagrid('getSelected');
 						parent.$.messager.confirm('确认','您确认想要删除记录吗？',function(r){    
						    if (r){    
						        	$.ajax({
													type:'POST',
													url:'admin/resource/deleteById',
													data:{id:row.id},
													dataType:'json',
													success:function(data){
															if(data && data.success){
																parent.$.messager.show({
																			title:'提示',
																			msg:data.message
																		});
																		$('#dg').datagrid('unselectAll'); 
																		$('#dg').datagrid('reload'); 
															}else{
																parent.$.messager.alert('提示',data.message);
															}
															
													},
													error:function(data){
														parent.$.messager.alert('提示',data.message);
													}
										});
						    }    
						}); 
 			} 
 			
 			
 function saveOrEdit(){
	 $.ajax({
			type:'POST',
			url:url,
			data:$('#fm').serialize(),
			dataType:'json',
			success:function(data){
					if(data && data.success){
								$('#dlg').dialog('close');
								parent.$.messager.show({
									title:'提示',
									msg:data.message
								});
								$('#dg').datagrid('unselectAll'); 
								$('#dg').datagrid('reload'); 
					}else{
						parent.$.messager.alert('提示',data.message);
					}
			},
			error:function(data){
				parent.$.messager.alert('提示',data.message);
			}
	 });
 }
 
 /**
	 * 修改文件状态
	 */
 function editFilePass(){
	 var rows = $('#dg').datagrid('getSelections');
	 if(rows.length <=0 || rows == null){
		 parent.$.messager.alert('提示','请至少选择一条记录!');
	 }else{
		 	var arr = new Array();
		 	for(var i=0;i<rows.length;i++){
		 		arr[i]=rows[i].id;
		 	}
		 	var ids = arr.join(',');
			 $.ajax({
				 type:'POST',
				 url:'admin/resource/editFilePass?ids='+ids,
				 dataType:'json',
				 success:function(data){
					 if(data && data.success){
						 $.messager.show({
							 title:'提示',
							 msg:data.message
						 });
						 $('#dg').datagrid('unselectAll'); 
						 $('#dg').datagrid('reload'); 
					 }else{
						 parent.$.messager.alert('提示',data.message);
					 }
				 },
				 error:function(data){
					 parent.$.messager.alert('提示',data.message);
				 }
			 });
	 }
 }